package com.huoshan.im.server.action.support;


import com.huoshan.im.server.ContextNaming;
import com.huoshan.im.server.messaging.MessageId;
import online.chazi.netkit.action.SocketAction;
import online.chazi.netkit.channel.NetkitFuture;
import online.chazi.netkit.messaging.Message;
import org.springframework.lang.Nullable;

/**
 * 说明：作者很懒，什么都没留下
 * Created by 火山九日 on 2020-04-26 09:55
 */
@SuppressWarnings("UnusedReturnValue")
public abstract class ActionSupport extends SocketAction {

    @Nullable
    public Long getUserId() {
        return (Long) getAttribute(ContextNaming.SESSION_USER_ID);
    }

    @Nullable
    public Integer getUserType() {
        return (Integer) getAttribute(ContextNaming.SESSION_USER_TYPE);
    }

    @Nullable
    public String getClientType() {
        return (String) getAttribute(ContextNaming.SESSION_CLIENT_TYPE);
    }

    public String getNickname() {
        return (String) getAttribute(ContextNaming.SESSION_USER_NICKNAME);
    }


    public void setAttribute(String key, Object value) {
        getSession().setAttribute(key, value);
    }

    @Nullable
    public Object getAttribute(String key) {
        return getSession().getAttribute(key);
    }

    public NetkitFuture sendMessage(MessageId messageId) {
        return super.getSession().sendMessage(new Message(messageId.id));
    }

    public NetkitFuture sendMessageAndClose(MessageId messageId) {
        return super.getSession().sendMessageAndClose(new Message(messageId.id));
    }

    public NetkitFuture sendMessage(Message message) {
        return super.getSession().sendMessage(message);
    }

    public NetkitFuture sendMessageAndClose(Message message) {
        return super.getSession().sendMessageAndClose(message);
    }

}
